package top.fengyulou.config.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import top.fengyulou.common.UserUtils;
import top.fengyulou.config.SysConfig;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 通用拦截
 */
@Component
public class CommonInterceptor implements HandlerInterceptor {

    @Resource
    private SysConfig sysConfig;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //系统域名
        request.setAttribute("dn", sysConfig.getDomainName());
        //登录状态是否登录
        request.setAttribute("isLogin", UserUtils.isLogin(request));
        //用户信息
        request.setAttribute(UserUtils.LOGIN_USER, UserUtils.getUser(request));
        return true;
    }
}
